package com.example.moban.view;

import android.content.Context;
import android.graphics.Typeface;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;


import com.example.moban.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 主页底部导航栏
 *
 * @author yql
 * @date: 2018/10/9.
 */
public class MainCustomBottomView extends RelativeLayout {
    private LayoutInflater inflater;

    @BindView(R.id.menu_class_group_img)
    AppCompatImageView mImageClassGroupImg;
    @BindView(R.id.menu_class_group_text)
    AppCompatTextView mTextClassGroup;
    @BindView(R.id.class_group_layout)
    LinearLayout mLayoutClassGroup;

    @BindView(R.id.menu_patriarch_course_img)
    AppCompatImageView mImagePatriarchCourseImg;
    @BindView(R.id.menu_patriarch_course_text)
    AppCompatTextView mTextPatriarchCourse;
    @BindView(R.id.menu_patriarch_course_layout )
    LinearLayout mLayoutPatriarchCourseLayout;

    @BindView(R.id.menu_live_course_img)
    AppCompatImageView mImageLiveCourseImg;
    @BindView(R.id.menu_live_course_text)
    AppCompatTextView mTextLiveCourse;
    @BindView(R.id.menu_live_course_layout )
    LinearLayout mLayoutLiveCourseLayout;

    @BindView(R.id.menu_person_center_img)
    AppCompatImageView mImagePersonCenterImg;
    @BindView(R.id.menu_person_center_text)
    AppCompatTextView mTextPersonCenter;


    @BindView(R.id.menu_person_center_layout )
    LinearLayout mLayoutPersonCenterLayout;

    public MainCustomBottomView(Context context) {
        this(context, null);
    }

    public MainCustomBottomView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MainCustomBottomView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    public void initView(Context context) {
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.view_main_custom_bottom, null);
        ButterKnife.bind(this, view);
        addView(view);
    }

    /**
     * 设置点击监听
     *
     * @param onClickListener
     */
    public void setMainOnClickListener(OnClickListener onClickListener) {
        mLayoutClassGroup.setOnClickListener(onClickListener);
        mLayoutPatriarchCourseLayout.setOnClickListener(onClickListener);
        mLayoutLiveCourseLayout.setOnClickListener(onClickListener);
        mLayoutPersonCenterLayout.setOnClickListener(onClickListener);
    }

    /**
     * 点击按钮改变状态
     */
    public void clickChangeView(int position) {
        mImageClassGroupImg.setImageResource(R.mipmap.icon_bjq1);
        mImagePatriarchCourseImg.setImageResource(R.mipmap.icon_jzkt1);
        mImageLiveCourseImg.setImageResource(R.mipmap.icon_zbkt1);
        mImagePersonCenterImg.setImageResource(R.mipmap.icon_grzx1);

        mTextClassGroup.setTextColor(getResources().getColor(R.color.color_000000));
        mTextPatriarchCourse.setTextColor(getResources().getColor(R.color.color_000000));
        mTextLiveCourse.setTextColor(getResources().getColor(R.color.color_000000));
        mTextPersonCenter.setTextColor(getResources().getColor(R.color.color_000000));
        mTextClassGroup.setTypeface( Typeface.DEFAULT );
        mTextPatriarchCourse.setTypeface( Typeface.DEFAULT );
        mTextLiveCourse.setTypeface( Typeface.DEFAULT );
        mTextPersonCenter.setTypeface( Typeface.DEFAULT );
        switch (position) {
            //班级圈
            case 0:
                mImageClassGroupImg.setImageResource( R.mipmap.icon_bjq2 );
                mTextClassGroup.setTextColor(getResources().getColor(R.color.color_229578));
                mTextClassGroup.setTypeface( Typeface.DEFAULT_BOLD );
                break;
            //家长课堂
            case 1:
                mImagePatriarchCourseImg.setImageResource(R.mipmap.icon_jzkt2 );
                mTextPatriarchCourse.setTextColor(getResources().getColor(R.color.color_229578));
                mTextPatriarchCourse.setTypeface( Typeface.DEFAULT_BOLD );
                break;
            //直播课程
            case 2:
                mImageLiveCourseImg.setImageResource(R.mipmap.icon_zbkt2);
                mTextLiveCourse.setTextColor(getResources().getColor(R.color.color_229578));
                mTextLiveCourse.setTypeface( Typeface.DEFAULT_BOLD );
                break;
            //个人中心
            case 3:
                mImagePersonCenterImg.setImageResource(R.mipmap.icon_grzx2);
                mTextPersonCenter.setTextColor(getResources().getColor(R.color.color_229578));
                mTextPersonCenter.setTypeface( Typeface.DEFAULT_BOLD );
                break;
            default:
                break;
        }
    }

    public LinearLayout getmLayoutClassGroup() {
        return mLayoutClassGroup;
    }

    public LinearLayout getmLayoutPatriarchCourseLayout() {
        return mLayoutPatriarchCourseLayout;
    }

    public LinearLayout getmLayoutLiveCourseLayout() {
        return mLayoutLiveCourseLayout;
    }

    public LinearLayout getmLayoutPersonCenterLayout() {
        return mLayoutPersonCenterLayout;
    }
}
